﻿using System;
using System.Net.Mail;
using System.Text;
using eCommerce.BusinessLogic;

namespace eCommerce.Site
{
    public partial class ContactUs : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string txtEnquiry = "a General Enquiry";
            txtWaterEnquiry.WatermarkText = "Your enquiry message for " + txtEnquiry;
        }

        protected void lnkbtnAdd_Click(object sender, EventArgs e)
        {
            string txtEnquiry = "General Enquiry";
            try
            {
                MailAddress from = new MailAddress("info@devsite.2beknown.co.uk");
                //MailAddress to = new MailAddress("info@devsite.2beknown.co.uk");
                MailAddress to = new MailAddress("tavis@2beknown.co.uk");
                MailMessage message = new MailMessage(from, to);
                //message.Bcc.Add("tavis@2beknown.co.uk");
                message.Subject = "Example eCommerce Website Contact Submission";
                StringBuilder sb = new StringBuilder();
                sb.Append(
                    "<html><body style=\"height:auto;margin:0 auto;\"><div style=\"font-family:Arial;font-size:11px;float:left;height:auto;margin:0 auto;color:#3F3F3F;padding:10px;\">");
                sb.Append(
                    " <img src=\"http://devsite.2beknown.co.uk/App_Themes/Default/graphics/logosm.jpg\" alt=\"Example eCommerce\" /><br /><br />");
                sb.Append("<b>Name: </b>" + txbName.Text + "<br />");
                sb.Append("<b>Contact Number: </b>" + txbContactNo.Text + "<br />");
                sb.Append("<b>Email address: </b>" + txbEmail.Text + "<br />");
                sb.Append("<b>Conpany Name: </b>" + txbCompany.Text + "<br />");
                sb.Append("<b>Enquiry Type: </b>" + txtEnquiry + "<br />");
                sb.Append("<b>Message: </b>" + txbMessage.Text + "<br />");
                if (chkNewsletter.Checked)
                {
                    sb.Append("<b>Permission to send newsletters:</b> Yes<br />");
                }
                if (chkNewsletter.Checked == false)
                {
                    sb.Append("<b>Permission to send newsletters:</b> No<br />");
                }
                sb.Append("</div></body></html>");
                message.Body = sb.ToString();
                message.IsBodyHtml = true;
                SmtpClient smtp = new SmtpClient("localhost", 25);
                smtp.Send(message);

                txbName.Text = "";
                txbContactNo.Text = "";
                txbEmail.Text = "";
                txbCompany.Text = "";
                txbMessage.Text = "";

                lblsent.Text = "Your detials have been submitted.";
            }
            catch (Exception ex)
            {
                ContactFormBL contactFormBL = new ContactFormBL();
                contactFormBL.SendTechError(DateTime.Now.ToLocalTime(), Page.Title, "devsite.2beknown.co.uk",
                                            "eCommerce Example Tech Error - Contact Page", txbEmail.Text, ex.Message,
                                            ex.StackTrace, ex.TargetSite);
                lblsent.Text ="Thier has been an error on this page, please make sure your details are filled out correctly!";
            }
        }
    }
}
    
        
    

